//
//  AKMediaEntry.m
//  CocoaBean
//
//  Created by sleeper on 5/31/10.
//  Copyright 2010 __MyCompany__, Inc. All rights reserved.
//

#import "AKEntry_Private.h"
#import "NSDictionary_DoubanAddition.h"
#import "AKMediaEntry.h"

@implementation AKMediaEntry

- (NSString *)summary
{
	return [self.dictionary akPropertyForKey:kAKEntryKeySummary valueKey:nil];
}

- (NSString *)publishDate
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"pubdate"];
}

- (NSArray *)akas
{
	// TODO: akas for a certain language
	if (_akas == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"aka"];
		_akas = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _akas;
}

- (NSArray *)akasForLanguage:(NSString *)language
{
	return nil;
}

- (void)dealloc
{
	AK_RELEASE(_translators);
	AK_RELEASE(_bookAuthors);
	AK_RELEASE(_tracks);
	AK_RELEASE(_singers);
	AK_RELEASE(_casts);
	AK_RELEASE(_akas);
	[super dealloc];
}

@end

@implementation AKMediaEntry (Book)

- (NSString *)isbn10
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"isbn10"];
}

- (NSString *)isbn13
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"isbn13"];
}

- (NSString *)bookTitle
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"title"];
}

- (NSString *)pages
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"pages"];
}

- (NSArray *)translators
{
	if (_translators == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"translator"];
		_translators = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _translators;
}

- (NSArray *)bookAuthors
{
	if (_bookAuthors == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"author"];
		_bookAuthors = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _bookAuthors;
}

- (NSString *)price
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"price"];
}

- (NSString *)publisher
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"publisher"];
}

- (NSString *)binding
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"binding"];
}

- (NSString *)authorIntro
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"author-intro"];
}

@end

@implementation AKMediaEntry (Music)

- (NSArray *)tracks
{
	if (_tracks == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"track"];
		_tracks = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _tracks;
}

- (NSArray *)singers
{
	if (_singers == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"singer"];
		_singers = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _singers;
}

- (NSString *)aka
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"aka"];
}

- (NSString *)numberOfDiscs
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"discs"];
}

- (NSString *)ean
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"ean"];
}

- (NSString *)allTracks
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"tracks"];
}

- (NSString *)albumTitle
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"title"];
}
			   
- (NSString *)publishDate
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"pubdate"];
}

- (NSString *)musicVersion
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"version"];
}

- (NSString *)media
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"media"];
}

@end

@implementation AKMediaEntry (Movie)

- (NSString *)year
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"year"];
}

- (NSArray *)writers
{
	if (_writers == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"writer"];
		_writers = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _writers;
}

- (NSArray *)directors
{
	if (_directors == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"director"];
		_directors = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _directors;
}

- (NSString *)language
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"language"];
}

- (NSString *)siteURL
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"website"];
}

- (NSString *)imdbURL
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"imdb"];
}

- (NSString *)country
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"country"];
}

- (NSString *)episodes
{
	return [self.dictionary akPropertyInArrayForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName valueKey:nil value:@"episodes"];
}

- (NSArray *)casts
{
	if (_casts == nil) {
		NSArray *array = [self.dictionary akCollectPropertyArraysForKey:kAKEntryKeyDoubanAttribute subkey:kAKEntrySubkeyName value:@"cast"];
		_casts = [[array valueForKey:kAKEntryKeySingleProperty] copy];
	}
	return _casts;
}

@end
